<?php

namespace App\Http\Service\Brand;

use App\Models\Category;
use App\Http\Service\BaseService;

class CategoryService  extends BaseService
{
    private $model;

    public function __construct(Category $model)
    {
        parent::__construct();
        $this->model = $model;
       
    }

    public function getList($request,$data=[])
    {
        $page = intval($request->input('page')) ?$request->input('page') :$this->cpage;
        $limit = intval($request->input('limit')) ?$request->input('limit') :$this->climit;
        $offset = ($page-1)*$limit;

        $data = $this->model->select()->get()->toArray();
        $count = count($data);
        $data =buildCategoryTree($data);

        $list= array_slice($data, $offset, $limit);
        $total_page=count($list);
        $result=[
            'page'=>$page,
            'limit'=>$limit,
            'count'=>$count,
            'total_page'=>$total_page,
            'data'=>$data,
        ];
        return $result;


    }
   
   
}
